package com.ra.landlord;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Index;
import org.hibernate.annotations.Where;

import com.ra.system.Version;

/**
 * 比simpleRroom更简单
 * @author zpx
 */
@Entity
@Table(name = "ra_room")
@Where(clause = "data_status = 1")
public class RoomDBVO implements Version, LandlordOwner{

	private Integer id;
	private String name;
	private List<FeeRule> feeRules;
	
	private Integer version;
	private LandlordOwnerUser landlordUser;
	private Integer status;
	////transient
	private Meter currentMeter;
	//transient
	private Meter lastMeter;
	// transient
	private Meter lastLastMeter;
	
	private Building building;
	
	private BuildingFloor buildingFloor;
	
	@Id
	@GeneratedValue
	@Column(name = "room_id")
	public Integer getId() {
		return id;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(name = "room_name")
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "createuserid")
	@Index(name="idx_ra_room_createuserid")
	public LandlordOwnerUser getLandlordUser() {
		return landlordUser;
	}

	public void setLandlordUser(LandlordOwnerUser landlordUser) {
		this.landlordUser = landlordUser;
	}

	@Column(name = "version_id")
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
	

	@Column(name = "data_status")
	@Index(name="idx_ra_room_creator_status",columnNames={"createuserid","data_status","buildings_id"})
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	
	@OneToMany(targetEntity=FeeRule.class, fetch=FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true, mappedBy="room")
	@Where(clause = "data_status=1")
	public List<FeeRule> getFeeRules() {
		return feeRules;
	}
	
	public void setFeeRules(List<FeeRule> feeRules) {
		this.feeRules = feeRules;
	}
	
	
	@Transient
	public Meter getCurrentMeter() {
		return currentMeter;
	}

	public void setCurrentMeter(Meter currentMeter) {
		this.currentMeter = currentMeter;
	}
	@Transient
	public Meter getLastMeter() {
		return lastMeter;
	}

	public void setLastMeter(Meter lastMeter) {
		this.lastMeter = lastMeter;
	}
	@Transient
	public Meter getLastLastMeter() {
		return lastLastMeter;
	}

	public void setLastLastMeter(Meter lastLastMeter) {
		this.lastLastMeter = lastLastMeter;
	}
	
	@ManyToOne(targetEntity=Building.class, fetch=FetchType.LAZY, optional=false)
	@JoinColumn(name = "buildings_id")
	@Index(name="idx_ra_room_buildings_id")
	public Building getBuilding() {
		return building;
	}

	public void setBuilding(Building building) {
		this.building = building;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "floor_id")
	@Index(name="idx_buildingFloor_id")
	public BuildingFloor getBuildingFloor() {
		return buildingFloor;
	}

	public void setBuildingFloor(BuildingFloor buildingFloor) {
		this.buildingFloor = buildingFloor;
	}
}
